#include "stdafx.h"
#include "Clock.h"

#ifdef WIN32
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif //_DEBUG
#endif //WIND32

namespace serika
{
	namespace ut
	{
		Clock::Clock()
			: mInterval(0)
			, mFrames(0)
			, mRunning(false)
		{
		}

		Clock::~Clock()
		{
		}

		void Clock::Start()
		{
			if (mRunning)
			{
				return;
			}

			mRunning = true;
			this->DoStart();
		}

		void Clock::SetInterval(size_t interval)
		{
			if (!mRunning)
			{
				mInterval = interval;
			}
		}

		void Clock::WaitForNextTick()
		{
			if (!mRunning)
			{
				return;
			}

			if (mInterval != 0)
			{
				this->Wait();
			}

			this->UpdateFrame();
			this->UpdateTime();
		}

		void Clock::UpdateFrame()
		{
			++mFrames;
		}
	}
}

